package com.wjp.banquet.common.util;

import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Validator;

/**
 * @Author 王君平
 * @Date 2023/11/19 14:54
 * @Description  https://blog.csdn.net/weixin_44012070/article/details/131684167
 */
public class ValidatorUtil {

    public static <T> BindingResult validate(Validator validator, T obj){
        BindException bindException = new BindException(obj,obj.getClass().getName());
        validator.validate(obj,bindException);            //调用校验方法进行校验
        return bindException.getBindingResult();                  //若没有异常，返回false
    }
}
